public class test12 {
    class Solution {
        public int monotoneIncreasingDigits(int n) {
            String[] strs = (n+"").split("");
            int index = strs.length;
            for(int i = strs.length-1;i>0;i--){
                if(Integer.parseInt(strs[i])<Integer.parseInt(strs[i-1])){
                    index = i;
                    strs[i-1] = (Integer.parseInt(strs[i-1])-1)+"";
                }
            }

            for(int i = index;i<strs.length;i++){
                strs[i] = "9";
            }

            return Integer.parseInt(String.join("",strs));
        }
    }
}
